/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package grest.view;
import grest.model.Entidad;
import grest.controller.CntrlrAbbm;
import grest.controller.CtrlrVistaSalon;
import java.awt.*;
import java.util.Observable;
import javax.swing.*;

/**
 *
 * @author rodrigo
 */
public class VistaABBM extends JPanel implements AbstractABBMView {
    public static final String alta = "Insertar";
    public static final String baja = "Eliminar";
    public static final String mod = "Guardar";
    private JTable tblTabla = new JTable();
    private JScrollPane scpTblTabla = new JScrollPane(tblTabla);
    private JPanel pnlDivisor = new JPanel();
    private JPanel pnlBotones = new JPanel();
    private JButton btnAlta = new JButton(alta);
    private JButton btnBaja = new JButton(baja);
    private JButton btnMod = new JButton(mod);
    private JLabel lblTitulo = new JLabel("Tabla Mozos");
    private Observable controller;
    public VistaABBM(String vista,Entidad e)
    {
        this.setLayout(new BorderLayout());
        this.add(scpTblTabla,BorderLayout.CENTER);
        pnlDivisor.setLayout(new GridLayout(1,1));
        pnlDivisor.add(pnlBotones);
        this.add(pnlDivisor, BorderLayout.NORTH);
        pnlBotones.setLayout(new GridLayout(1, 3));
        lblTitulo.setHorizontalAlignment(JLabel.CENTER);
        this.add(lblTitulo,BorderLayout.SOUTH);
        pnlBotones.add(btnAlta);
        pnlBotones.add(btnBaja);
        pnlBotones.add(btnMod);
        CntrlrAbbm eventHandler = new CntrlrAbbm(this, vista,e );
        btnAlta.addActionListener(eventHandler);
        btnBaja.addActionListener(eventHandler);
        btnMod.addActionListener(eventHandler);
        controller=(Observable)eventHandler;
    }
    
    @Override
    public void paintComponent(Graphics g)
    {
        super.paintComponent(g);    
    }

    @Override
    public JComponent getControls(String nombre) {
       if(nombre.equals("tblTabla")) return tblTabla;
       else if(nombre.equals("btnAlta")) return btnAlta;
       else if(nombre.equals("btnBaja")) return btnBaja;
       else if(nombre.equals("btnMod")) return btnMod;
       else if(nombre.equals("lblTitulo")) return lblTitulo;
       else return null;
    }
    public Observable getController(){
        return controller;
    }
}
